package request;

import com.example.demo09Tomcat.HelloServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*

     2: 获取请求头数据 :
        *方法:
          String getHeader(String name): 通过请求头的名称获取请求头的值
          Enumeration<String> getHeaderNames(): 获取所有的请求头名称
          
*/

@WebServlet("/demo03")
public class Servletdemo02 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
       //演示获取请求头数据: user-agent
        String aa = request.getHeader("user-agent");
        //判断agent的浏览器版本
        if (aa.contains("Chrome")){
            System.out.println("谷歌");
        }else if (aa.contains("Firefox")){
            System.out.println("火狐浏览器");
        }
    }
}
